From: Florian Müllner Date: Sun, 26 Feb 2017 23:14:09 +0000 (+0100) Subject: messageTray: Add optional datetime parameter to notifications X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~1013^2^2~510 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=0569bb18f5b4b594777a3af2f5a8271d24467a14;p=gnome-shell.git messageTray: Add optional datetime parameter to notifications Since the last notification redesign, we've been showing the time a notification was received in the calendar drop-down. However as the time is in fact added by the NotificationSection, it is actually the time a notification was added to the list. Usually that difference is not significant, except when previously received notifications are restored on startup. In order to be able to address those cases, we need a time that is associated with the notification itself, so add a datetime property that defaults to the current time, but may be set from an optional parameter as well. https://bugzilla.gnome.org/show_bug.cgi?id=775799 --- diff --git a/js/ui/calendar.js b/js/ui/calendar.js index 2ed812613..70252e2ec 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -946,8 +946,8 @@ const NotificationSection = new Lang.Class({ !Main.sessionMode.isGreeter; }, - _createTimeLabel: function() { - let label = Util.createTimeLabel(new Date()); + _createTimeLabel: function(datetime) { + let label = Util.createTimeLabel(datetime); label.style_class = 'event-time', label.x_align = Clutter.ActorAlign.END; return label; @@ -970,13 +970,13 @@ const NotificationSection = new Lang.Class({ _onNotificationAdded: function(source, notification) { let message = new NotificationMessage(notification); - message.setSecondaryActor(this._createTimeLabel()); + message.setSecondaryActor(this._createTimeLabel(notification.datetime)); let isUrgent = notification.urgency == MessageTray.Urgency.CRITICAL; let updatedId = notification.connect('updated', Lang.bind(this, function() { - message.setSecondaryActor(this._createTimeLabel()); + message.setSecondaryActor(this._createTimeLabel(notification.datetime)); this.moveMessage(message, isUrgent ? 0 : this._nUrgent, this.actor.mapped); })); let destroyId = notification.connect('destroy', Lang.bind(this, diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 4f1ab7fea..fe1b4d8e7 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -368,6 +368,7 @@ const Notification = new Lang.Class({ secondaryGIcon: null, bannerMarkup: false, clear: false, + datetime: null, soundName: null, soundFile: null }); @@ -375,6 +376,11 @@ const Notification = new Lang.Class({ this.bannerBodyText = banner; this.bannerBodyMarkup = params.bannerMarkup; + if (params.datetime) + this.datetime = params.datetime; + else + this.datetime = GLib.DateTime.new_now_local(); + if (params.gicon || params.clear) this.gicon = params.gicon;